package a02_链表;

/**
 * <p>
 * a05_两两交换链表中的节点复习6
 * </p>
 *
 * @author flyduck
 * @since 2025/4/10
 */
public class a05_两两交换链表中的节点复习6 {
    public ListNode swapPairs(ListNode head) {
        ListNode dummyNode = new ListNode(0);
        dummyNode.next = head;

        ListNode curNode = dummyNode;
        while (curNode != null && curNode.next != null && curNode.next.next != null){
            ListNode oneNode = curNode.next;
            ListNode secondNode = oneNode.next;
            ListNode thirdNode = secondNode.next;

            curNode.next = secondNode;
            secondNode.next = oneNode;
            oneNode.next = thirdNode;

            curNode = oneNode;
        }

        return dummyNode.next;
    }
}
